package com.pan.controller;


import com.pan.entity.OperationStockHistory;
import com.pan.entity.Result;
import com.pan.service.OperationStockHistoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

@Controller
@RequestMapping("/stockHistory")
public class StockHistoryController {
    @Resource
    private OperationStockHistoryService stockHistoryService;

    @ResponseBody
    @GetMapping("/select/stockId/{stockId}")
    public Result<List<OperationStockHistory>> selectByStockId(@CookieValue("adminTicket") String adminTicket,
                                                               @PathVariable Long stockId){
        Result<List<OperationStockHistory>> result = stockHistoryService
                .selectByStockId(adminTicket,stockId);
        return result;
    }

    @ResponseBody
    @GetMapping("/select/adminId/{adminId}")
    public Result<List<OperationStockHistory>> selectByAdminId(@CookieValue("adminTicket") String adminTicket,
                                                               @PathVariable Long adminId){
        Result<List<OperationStockHistory>> result = stockHistoryService
                .selectByAdminId(adminTicket,adminId);
        return result;
    }

    @ResponseBody
    @GetMapping("/select/date/{year}/{month}/{day}")
    public Result<List<OperationStockHistory>> selectByDate(@CookieValue("adminTicket") String adminTicket,
                                                            @PathVariable String year,
                                                            @PathVariable String month,
                                                            @PathVariable String day){
        Result<List<OperationStockHistory>> result;
        try {
            result = stockHistoryService
                    .selectByUpdateDate(adminTicket,year,month,day);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        return result;
    }

}
